package com.mdb.open.trade.facade;

import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.api.enums.ApiEnum;
import com.mdb.bc.utils.BeanConvertUtil;
import com.mdb.open.common.enums.ProductCodeEnum;
import com.mdb.open.trade.domain.po.product.CustProd;
import com.mdb.open.trade.domain.vo.product.CustProdVo;
import com.mdb.open.trade.service.product.CustProdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liuyi
 * @date 2019/07/13
 **/
@Service
public class ProdFacade {

    @Autowired
    private CustProdService custProdService;

    /**
     * 根据appId产品app配置信息
     */
    public ListResultEx<CustProdVo> queryCustProdList(String customerCode) {

        List<CustProd> custProds = custProdService.listByCustomerCode(customerCode);
        List<CustProdVo> custProdVos = BeanConvertUtil.convertList(custProds, custProd -> {
            CustProdVo custProdVo = new CustProdVo();
            custProdVo.setCustomerCode(custProd.getCustomerCode());
            custProdVo.setCustomerName(custProd.getCustomerName());
            custProdVo.setProdCode(custProd.getProdCode());
            custProdVo.setProdName(ApiEnum.parseToText(ProductCodeEnum.class, custProd.getProdCode()));
            custProdVo.setStatus(custProd.getStatus());
            custProdVo.setOpenTime(custProd.getOpenTime());
            custProdVo.setEffTime(custProd.getEffTime());
            custProdVo.setOpenType(custProd.getOpenType());
            custProdVo.setWhitelist(custProd.getWhitelist());
            custProdVo.setDockingType(custProd.getDockingType());
            custProdVo.setRemark(custProd.getRemark());
            custProdVo.setCreateTime(custProd.getCreateTime());
            custProdVo.setUpdateTime(custProd.getUpdateTime());
            return custProdVo;
        });
        return ListResultEx.ok(custProdVos);
    }

}